package com.holyn.guofang.presenter.distinguish;

import com.holyn.guofang.model.webhttp.RetrofitManager;
import com.holyn.guofang.model.webhttp.observable.DataDictionaryObservable;
import com.holyn.guofang.model.webhttp.wo.ProductGroupWo;
import com.holyn.guofang.model.webhttp.wo.ProductServiceWo;
import com.holyn.guofang.presenter.BaseView;

import io.reactivex.annotations.NonNull;
import io.reactivex.functions.Consumer;

/**
 * Created by Holyn on 2017/7/11.
 */

public class ProductClassfiyPresenter extends ProductClassfiyContract.Presenter{
    private DataDictionaryObservable dataDictionaryObservable;
    private ProductClassfiyContract.GroupView groupView = null;
    private ProductClassfiyContract.ServiceView serviceView = null;

    public ProductClassfiyPresenter(BaseView baseView) {
        super(baseView);
        dataDictionaryObservable = RetrofitManager.getCommonObservable(DataDictionaryObservable.class);
    }

    @Override
    public void addGroupView(ProductClassfiyContract.GroupView groupView) {
        this.groupView = groupView;
    }

    @Override
    public void addServiceView(ProductClassfiyContract.ServiceView serviceView) {
        this.serviceView = serviceView;
    }

    @Override
    public void postProductGroupList(int requestAction, String typeCode, String groupCode, Integer pageSize, Integer page) {
        getCommonObservable(requestAction, dataDictionaryObservable.productGroupList(typeCode, groupCode, pageSize, page))
            .subscribe(new Consumer<ProductGroupWo>() {
                @Override
                public void accept(@NonNull ProductGroupWo productGroupWo) throws Exception {
                    groupView.responseSuccess(requestAction, productGroupWo);
                }
            });
    }

    @Override
    public void postProductServiceList(int requestAction, String typeCode, String groupCode, String productName, Integer pageSize, Integer page) {
        getCommonObservable(requestAction, dataDictionaryObservable.productServiceList(typeCode, groupCode, productName, pageSize, page))
            .subscribe(new Consumer<ProductServiceWo>() {
                @Override
                public void accept(@NonNull ProductServiceWo productServiceWo) throws Exception {
                    serviceView.responseSuccess(requestAction, productServiceWo);
                }
            });
    }
}
